import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;


public class ProcessManager {
	public static int[] ports = {8000, 8001, 8002, 8003, 8004, 8005, 8006, 8007, 8008, 8009};
	public static String serverName = "localhost"; 
	public static int numProcess;
	private static int snapshotName = 1;
	
	public static void main(String[] args) throws IOException {
		deleteFolder(new File("files/"));
		numProcess = Integer.parseInt(args[0]);
		while (true) {
			System.out.print("Process: ");
			BufferedReader bufferRead = new BufferedReader(new InputStreamReader(System.in));
		    String s = bufferRead.readLine();
		    int processName = Integer.parseInt(s);
		    if (processName >= numProcess) {
		    	System.out.println("No Process found");
		    } else {
		    	new Sender(new SnapshotTriggeringMessage(snapshotName++, processName));
		    }
		}
		
	}
	
	public static void deleteFolder(File folder) {
	    File[] files = folder.listFiles();
	    if(files!=null) { //some JVMs return null for empty dirs
	        for(File f: files) {
	            if(!f.isDirectory()) {
	                f.delete();
	            }
	        }
	    }
	}
	
	
}
